"use strict";
// const nodemailer = require("nodemailer");
import nodemailer from 'nodemailer';

// async..await is not allowed in global scope, must use a wrapper
async function send(sendInfo) {
  // Generate test SMTP service account from ethereal.email
  // Only needed if you don't have a real mail account for testing
  // let testAccount = await nodemailer.createTestAccount();

  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    host: "smtp.qq.com",
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: '675603402@qq.com', // generated ethereal user
      pass: 'gvxeasxqeaksbdci', // generated ethereal password
    },
  });
  //#endregion
  const url = 'https://baidu.com/';

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: '"uu网" <675603402@qq.com>', // sender address
    to: `${sendInfo.email}`, // list of receivers
    subject: "[uu网]找回您的账户密码", // Subject line
    // text: "Hello world?", // plain text body
    html: `
      <div>
        尊敬的uu网用户，您好！<br/><br/>
        您在访问uu网时点击了“忘记密码”链接，这是一封密码重置确认邮件。<br/><br/>
        您可以通过点击以下链接重置账户密码：<br/><br/>
        <a href="${url}">${url}</a><br/><br/>
        为保障您的账号安全，请在24小时内点击该链接，您也可以将链接复制到浏览器地址栏访问。 若如果您并未尝试修改密码，请忽略本邮件，由此给您带来的不便请谅解。<br/><br/>
        本邮件由系统自动发出，请勿直接回复！
      </div>
    `, // html body
  });

  return "Message sent: %s", info.messageId;
  // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

  // Preview only available when sending through an Ethereal account
  // console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
  // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}

// main().catch(console.error);

export default send;